//防抖：在一段时间内，事件只会触发最后一次
function debounce(fn, delay) {
  let timeout = null
  return function () {
    let context = this
    let args = arguments
    clearTimeout(timeout)
    timeout = setTimeout(() => {
      fn.apply(context, args)
    }, delay)
  }
}
//节流：事件按照一段时间的间隔进行触发
function throttle(fn, delay) {
  let pre = 0
  return function () {
    let now = new Date()
    if (now - pre > delay) {
      let context = this
      let args = arguments
      fn.apply(context, args)
      pre = now
    }
  }
}
